package middleware

import (
	"notes/config"
	"notes/util"

	"github.com/gin-gonic/gin"
)

func CheckToken(c *gin.Context) {
	token := c.DefaultQuery("_token", "")
	data, err := util.ParseToken(token, config.Conf.Server.TokenSecret)
	if err != nil {
		util.JSON(c, err, nil)
		c.Abort()
		return
	}

	c.Set("tokenData", data)
	c.Next()
}
